

package ubo.master1.jeupoker.gui;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;

/**
 * 
 * Donnees d 'un utilisateur et son affichage 
 */
public class PaletteJoueur extends JPanel {

    /** Filled dealer button image when player is dealer. */
    private static final Icon BUTTON_PRESENT_ICON =
            AcceeCarts.getIcon("/images/card_04.png");
    /** Empty dealer button image when player is not dealer. */
    private static final Icon BUTTON_ABSENT_ICON =
            AcceeCarts.getIcon("/images/button_absent.png");
    private static final Icon CARD_PLACEHOLDER_ICON =
            AcceeCarts.getIcon("/images/card_placeholder.png");
    private static final Icon CARD_BACK_ICON =
            AcceeCarts.getIcon("/images/card_back.png");
    private static final Icon CARD_BACK_ICONT1 =
            AcceeCarts.getIcon("/images/card_45.png");
    private static final Icon CARD_BACK_ICONT2 =
            AcceeCarts.getIcon("/images/card_back.png");
//      private static final Icon CONTROLLEUR8_IMG = 
//            AcceeCarts.getIcon("/images/Controlleur.png");
    /** The border. */
    private static final Border BORDER = new EmptyBorder(10, 10, 10, 10);
    /** The label with the player's name. */
    private JLabel nameLabel;
    /** The label with the player's amount of cash. */
    private JLabel cashLabel;
    /** The label with the last action performed. */
    private JLabel actionLabel;
    /** The label with the player's current bet. */
    private JLabel betLabel;
    /** The label for the first hole card. */
    private JLabel card1Label;
    /** The label for the second hole card. */
    private JLabel card2Label;
    /** The label for the dealer button image. */
    private JLabel dealerButton;

    /**
     * Constructor.
     * 
     * @param player
     *     Le joueur.
     */
    public PaletteJoueur(String userFace) {
        setBorder(BORDER);
        this.setOpaque(false);
        setLayout(new GridBagLayout());
        GridBagConstraints gc = new GridBagConstraints();

        nameLabel = new MyLabel();
        cashLabel = new MyLabel();
        actionLabel = new MyLabel();
        betLabel = new MyLabel();
        card1Label = new JLabel(CARD_BACK_ICONT1);
        card2Label = new JLabel(CARD_BACK_ICONT2);
        dealerButton = new JLabel(BUTTON_ABSENT_ICON);

//        gc.gridx = 0;
//        gc.gridy = 0;
//        gc.gridwidth = 2;
//        gc.gridheight = 1;
//        gc.weightx = 1.0;
//        gc.weighty = 1.0;
//        gc.anchor = GridBagConstraints.CENTER;
//        gc.fill = GridBagConstraints.NONE;
//        add(dealerButton, gc);
        gc.gridx = 0;
        gc.gridy = 0;
        gc.gridwidth = 2;
        gc.gridheight = 1;
        gc.weightx = 1.0;
        gc.weighty = 1.0;
        gc.anchor = GridBagConstraints.CENTER;
        gc.fill = GridBagConstraints.NONE;
        if (userFace != null) {
            JoueurIcon test = new JoueurIcon(userFace);
            add(test, gc);
        }
        gc.gridx = 0;
        gc.gridy = 1;
        gc.gridwidth = 1;
        gc.gridheight = 1;
        gc.insets = new Insets(1, 1, 1, 1);
        gc.anchor = GridBagConstraints.CENTER;
        gc.fill = GridBagConstraints.HORIZONTAL;
        gc.weightx = 1.0;
        gc.weighty = 1.0;
        nameLabel.setText("User");
        add(nameLabel, gc);


        gc.gridx = 1;
        gc.gridy = 1;
        gc.gridwidth = 1;
        gc.gridheight = 1;
        gc.weightx = 1.0;
        gc.weighty = 1.0;
        gc.anchor = GridBagConstraints.CENTER;
        gc.fill = GridBagConstraints.HORIZONTAL;
        cashLabel.setText("30 $");
        add(cashLabel, gc);
        gc.gridx = 0;
        gc.gridy = 2;
        gc.gridwidth = 1;
        gc.gridheight = 1;
        gc.weightx = 1.0;
        gc.weighty = 1.0;
        gc.anchor = GridBagConstraints.CENTER;
        gc.fill = GridBagConstraints.HORIZONTAL;
        actionLabel.setText("action mise");
        add(actionLabel, gc);
        gc.gridx = 1;
        gc.gridy = 2;
        gc.gridwidth = 1;
        gc.gridheight = 1;
        gc.weightx = 1.0;
        gc.weighty = 1.0;
        gc.anchor = GridBagConstraints.CENTER;
        gc.fill = GridBagConstraints.HORIZONTAL;
        betLabel.setText("6 $");
        add(betLabel, gc);
        gc.gridx = 0;
        gc.gridy = 3;
        gc.gridwidth = 1;
        gc.gridheight = 1;
        gc.weightx = 1.0;
        gc.weighty = 1.0;

        gc.anchor = GridBagConstraints.CENTER;
        gc.fill = GridBagConstraints.NONE;
        add(card1Label, gc);
        gc.gridx = 1;
        gc.gridy = 3;
        gc.gridwidth = 1;
        gc.gridheight = 1;
        gc.weightx = 1.0;
        gc.weighty = 1.0;
        gc.anchor = GridBagConstraints.CENTER;
        gc.fill = GridBagConstraints.NONE;
        add(card2Label, gc);

    }

    /**
     * Creer un lablel .
     * 
     */
    private static class MyLabel extends JLabel {

        public MyLabel() {
            setBorder(UIConfiguration.LABEL_BORDER);
            setForeground(UIConfiguration.TEXT_COLOR);
            setHorizontalAlignment(JLabel.HORIZONTAL);
            setText(" ");
        }
    } // MyLabel
}
